/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.hnilica.cisteniulic.dto;

import java.io.Serializable;
import java.util.Comparator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
import org.apache.commons.collections.comparators.NullComparator;

/**
 *
 * @author swosh
 */
@Entity
@Table(name = "cis_orientacni")
@IdClass(CisOrientacniId.class)
public class CisOrientacni implements Serializable {

    private static final long serialVersionUID = 4L;
    private String nazUlice;
    private String nazAkce;
    private int cislo;
    private static Comparator<String> nullSafeComparator = new NullComparator(String.CASE_INSENSITIVE_ORDER);

    @Id
    @Column(name = "naz_ulice", nullable = false)
    public String getNazUlice() {
        return nazUlice;
    }

    public void setNazUlice(String nazUlice) {
        this.nazUlice = nazUlice;
    }

    @Id
    @Column(name = "naz_akce", nullable = false)
    public String getNazAkce() {
        return nazAkce;
    }

    public void setNazAkce(String nazAkce) {
        this.nazAkce = nazAkce;
    }

    @Id
    @Column(name = "cislo", nullable = false)
    public int getCislo() {
        return cislo;
    }

    public void setCislo(int cislo) {
        this.cislo = cislo;
    }

    /**
     *
     * @param cisOrientacni
     * @return
     */

    public int compareTo(CisOrientacni cisOrientacni) {

        int result = nullSafeComparator.compare(this.getNazAkce(), cisOrientacni.getNazAkce());
        if (result > 0) {
            return 1;
        } else if (result < 0) {
            return -1;
        } else {
            result = nullSafeComparator.compare(this.getNazUlice(), cisOrientacni.getNazUlice());
            if (result > 0) {
                return 1;
            } else if (result < 0) {
                return -1;
            } else {
                if (this.getCislo() > cisOrientacni.getCislo()) {
                    return 1;
                } else if (this.getCislo() < cisOrientacni.getCislo()) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || (object.getClass() != this.getClass())) {
            return false;
        }
        CisOrientacni cisOrientacni = (CisOrientacni) object;
        int result = nullSafeComparator.compare(this.getNazAkce(), cisOrientacni.getNazAkce());
        if (result != 0) {
            return false;
        }
        result = nullSafeComparator.compare(this.getNazUlice(), cisOrientacni.getNazUlice());
        if (result != 0) {
            return false;
        }
        if (this.getCislo() != cisOrientacni.getCislo()) {
            return false;
        }
        return true;
    }
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (null == nazAkce ? 0 : nazAkce.hashCode());
        hash = 31 * hash + (null == nazUlice ? 0 : nazUlice.hashCode());
        hash = 31 * hash + cislo;
        return hash;
    }
}
